package com.xkdx.guangguang.fragment.shop.brandofshop;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.xkdx.guangguang.module.network.AbsModule;
import com.xkdx.guangguang.shareclass.Shop;

public class BrandsOfShopModule extends AbsModule {
	List<Shop> list;

	@Override
	public void parseData() throws Exception {
		backJson = (JSONArray) result;
		try {
			for (int i = 0; i < backJson.length(); i++) {
				jsonObj = (JSONObject) backJson.get(i);
				String sortOfAct = jsonObj.getString("Act");
				if (sortOfAct.equals("getChildShopList")) {
					list = parseChildList(jsonObj.getJSONObject("Content"));
				}

			}
		} catch (Exception e) {
			throw e;
		}

	}

	private List<Shop> parseChildList(JSONObject person) throws Exception {
		ArrayList<Shop> list = new ArrayList<Shop>();
		try {
			JSONObject stuts = (JSONObject) person.get("Result");
			// Log.i(TAG, stuts.toString());
			JSONArray jsonArray = (JSONArray) stuts.getJSONArray("ListInfo");
			for (int i = 0; i < jsonArray.length(); i++) {
				JSONObject item = (JSONObject) jsonArray.opt(i);
				Shop shop = new Shop();
				shop.setDistance(item.getString("Distance"));
				shop.setLogo(item.getString("Logo"));
				shop.setShopID(item.getString("ShopID"));
				shop.setShopName(item.getString("ShopName"));
				shop.setBrandID(item.getString("BrandID"));
				shop.setShopType(item.getString("ShopType"));
				shop.setCard(item.getString("Card"));
				shop.setNewProductCount(item.getString("NewProductCount"));
				shop.setDiscountCount(item.getString("DiscountCount"));
				list.add(shop);

			}

		} catch (Exception e) {
			throw e;
		}

		return list;
	}

}
